package com.two.screen.water.balance.net.api

import com.lzy.okgo.OkGo
import com.lzy.okrx2.adapter.ObservableBody
import com.two.screen.water.balance.bean.*
import com.two.screen.water.balance.bean.database.ServerOrderResult
import com.two.screen.water.balance.bean.database.ServerVipInfo
import com.two.screen.water.balance.net.JsonConvert
import com.two.screen.water.balance.utils.Params
import com.two.screen.water.balance.utils.RxUtils
import io.reactivex.Observable
import java.util.*

object NormalApi {
    fun getData(params: SortedMap<String, Any?>, url: String?): Observable<BaseBean<BaseData>> {
        return OkGo.post<BaseBean<BaseData>>(url) //
            .params(Params.getParams(params))
            .headers(Params.getHeads(sortedMapOf()))
            .converter(object : JsonConvert<BaseBean<BaseData>>() {}) //
            .adapt(ObservableBody<BaseBean<BaseData>>()) //
            .compose(RxUtils.io())
    }
    fun getServerOrderData(params: SortedMap<String, Any?>, url: String?): Observable<BaseBean<OrderServerBean>> {
        return OkGo.post<BaseBean<OrderServerBean>>(url) //
            .params(Params.getParams(params))
            .headers(Params.getHeads(sortedMapOf()))
            .converter(object : JsonConvert<BaseBean<OrderServerBean>>() {}) //
            .adapt(ObservableBody<BaseBean<OrderServerBean>>()) //
            .compose(RxUtils.io())
    }
    fun postPay(params: SortedMap<String, Any?>, url: String?): Observable<BaseBean<ServerOrderResult>> {
        return OkGo.post<BaseBean<ServerOrderResult>>(url) //
            .params(Params.getParams(params))
            .headers(Params.getHeads(sortedMapOf()))
            .converter(object : JsonConvert<BaseBean<ServerOrderResult>>() {}) //
            .adapt(ObservableBody<BaseBean<ServerOrderResult>>()) //
            .compose(RxUtils.io())
    }
    fun getVipInfo(params: SortedMap<String, Any?>, url: String?): Observable<BaseBean<ServerVipInfo>> {
        return OkGo.post<BaseBean<ServerVipInfo>>(url) //
            .params(Params.getParams(params))
            .headers(Params.getHeads(sortedMapOf()))
            .converter(object : JsonConvert<BaseBean<ServerVipInfo>>() {}) //
            .adapt(ObservableBody<BaseBean<ServerVipInfo>>()) //
            .compose(RxUtils.io())
    }

    fun getLoginData(params: SortedMap<String, Any?>, url: String?): Observable<BaseBean<LoginBean>> {
        return OkGo.post<BaseBean<LoginBean>>(url) //
            .params(Params.getParams(params))
            .converter(object : JsonConvert<BaseBean<LoginBean>>() {}) //
            .adapt(ObservableBody<BaseBean<LoginBean>>()) //
            .compose(RxUtils.io())
    }

    fun getIndexData(params: SortedMap<String, Any?>, url: String?): Observable<BaseBean<IndexBean>> {
        return OkGo.post<BaseBean<IndexBean>>(url) //
            .params(Params.getParams(params))
            .converter(object : JsonConvert<BaseBean<IndexBean>>() {}) //
            .adapt(ObservableBody<BaseBean<IndexBean>>()) //
            .compose(RxUtils.io())
    }

}